<?php /* D:\phpStudy\PHPTutorial\WWW\laravel-admin\resources\views/admin/channel/category.blade.php */ ?>
<div id="app">
    <section class="content-header">
        <h1>
            <small><?php echo e($listName, false); ?></small>
        </h1>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-header with-border">
                        <div class="box-tools">
                            <div class="btn-group pull-right" style="margin-right: 5px">
                                <a href="/admin/channel/addCategory?cha_id=<?php echo e($cha_id, false); ?>" class="btn btn-sm btn-default" title="添加分类"><span class="hidden-xs">添加分类</span></a>
                            </div>
                        </div>

                        <span>
   
    <div class="btn-group">

    </div>
    <a class="btn btn-sm btn-primary grid-refresh" title="刷新"><i class="fa fa-refresh"></i><span class="hidden-xs"> 刷新</span></a>
  </span>
                    </div>

                    <!-- /.box-header -->
                    <!--数据列表开始   -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <thead >
                            <tr >
                                <th>分类id </th>
                                <th>分类名称</th>
                                <th>类目码名称</th>
                                <th>分类logo</th>
                                <th>是否删除</th>
                                <th>是否隐藏</th>
                                <th>所属渠道</th>
                                <th>分类级别</th>
                                <th>查看子类</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody>

                            <?php if(!empty($list)): ?>
                                <?php $__currentLoopData = $list; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                        <tr id="tr<?php echo e($v['cate_id'], false); ?>"  class="trpid<?php echo e($v['pid'], false); ?>" >
                                            <td >
                                                <?php echo e($v['cate_id'], false); ?>

                                            </td>
                                            <td >
                                                <?php echo e($v['level_str'], false); ?><?php echo e($v['cate_name'], false); ?>

                                            </td>
                                            <td >
                                                <?php echo e($v['cate_code'], false); ?>

                                            </td>
                                            <td >
                                                <img src="<?php echo e($v['cate_pic'], false); ?>" width="100">
                                            </td>

                                            <td >
                                                <?php if($v['is_del']==0): ?>
                                                    <span   style="color:blue;">否</span>
                                                <?php else: ?>
                                                    <span   style="color:red;">是</span>
                                                <?php endif; ?>
                                            </td>
                                            <td >
                                                <?php if($v['is_hidden']==1): ?>
                                                    <span   style="color:blue;">否</span>
                                                <?php else: ?>
                                                    <span   style="color:red;">是</span>
                                                <?php endif; ?>
                                            </td>

                                            <td >
                                                <?php echo e($v['cha_name'], false); ?>

                                            </td>
                                            <td >
                                                <?php echo e($v['level'], false); ?>

                                            </td>
                                            <td >
                                                <?php if($v['is_son']==0): ?>
                                                    <span onclick="showChild(<?php echo e($v['cate_id'], false); ?>)" class="showChild" style="border-radius:5px;padding:5px;background:#00a7d0;color:#f9f9f9" data-id="<?php echo e($v['cate_id'], false); ?>">查看子分类</span>
                                                <?php else: ?>
                                                    <span style="border-radius:5px;padding:5px;background:#00a7d0;color:red;" data-id="<?php echo e($v['cate_id'], false); ?>">无子类</span>
                                                <?php endif; ?>
                                            </td>
                                            <td >
                                                <a href="/admin/channel/editCategory?id=<?php echo e($v['cate_id'], false); ?>">
                                                    编辑
                                                </a>
                                            </td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <!--数据列表结束-->



                    <!-- /.box-body -->
                </div>
            </div>
        </div>

    </section>
</div>

<script data-exec-on-popstate>
    $(function () {
        $("#cha_id").val("<?php if(!empty($where['cha_id'])): ?><?php echo e($where['cha_id'], false); ?><?php endif; ?>");

        //tr选中样式控制
        $('.grid-row-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () {
            if (this.checked) {
                $(this).closest('tr').css('background-color', '#ffffd5');
            } else {
                $(this).closest('tr').css('background-color', '');
            }
        });





        $('.grid-select-all').iCheck({checkboxClass:'icheckbox_minimal-blue'});

        $('.grid-select-all').on('ifChanged', function(event) {
            if (this.checked) {
                $('.grid-row-checkbox').iCheck('check');
            } else {
                $('.grid-row-checkbox').iCheck('uncheck');
            }
        });



        //刷新
        $('.grid-refresh').on('click', function() {
            $.pjax.reload('#pjax-container');
            toastr.success('刷新成功 !');
        });

        //搜索
        $('.shaixuan-filter-btn').unbind('click');
        $('.shaixuan-filter-btn').click(function (e) {
            if ($('#filter-box').is(':visible')) {
                $('#filter-box').addClass('hide');
            } else {
                $('#filter-box').removeClass('hide');
            }
        });

        // $(".showChild").click(function(e){
        //     var id=$(this).attr('data-id');
        //     $(".trpid"+id).toggle();
        // });
    });

    function showChild(id) {
        console.log(id);
        var child_length=$(".trpid"+id).length;
        if(child_length>0) {
            $(".trpid"+id).toggle();
            return false;
        }
        $.ajax({
            url:'/admin/channel/getChildHtml',
            data:{id,id},
            type:'get',
            dataType:'json',
            success: function (m) {
                if(m.status==1){
                    $(".trpid"+id).remove();
                    $("#tr"+id).after(m.data.html);
                }else{

                }
            }
        });
    }


</script>